/*
 * *******************************************************************
 *   @项目名称: BHex Android
 *   @文件名称: OtcOrderApi.java
 *   @Date: 19-1-14 上午10:50
 *   @Author: ppzhao
 *   @Description:
 *   @Copyright（C）: 2019 BlueHelix Inc.   All rights reserved.
 *   注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的.
 *  *******************************************************************
 */

package io.bhex.sdk.otc;

import io.bhex.baselib.network.BParamsBuilder;
import io.bhex.baselib.network.HttpUtils;
import io.bhex.baselib.network.listener.SimpleResponseListener;
import io.bhex.baselib.network.params.PostParams;
import io.bhex.baselib.network.response.BaseResponse;
import io.bhex.baselib.network.response.ResultResponse;
import io.bhex.baselib.utils.MD5Utils;
import io.bhex.sdk.OTCUrls;
import io.bhex.sdk.otc.bean.OrderCreateResponse;
import io.bhex.sdk.otc.bean.OrderHistoryResponse;
import io.bhex.sdk.otc.bean.OrderPendingCountResponse;
import io.bhex.sdk.otc.bean.OrderPendingListResponse;
import io.bhex.sdk.otc.bean.OtcCreateOrderRequestBean;
import io.bhex.sdk.otc.bean.OtcOrderInfoResponse;

public class OtcOrderApi {
    /**
     * 获取广告列表
     * @param requestBean
     * @param listener
     */
    public static void orderCreate(OtcCreateOrderRequestBean requestBean, SimpleResponseListener<OrderCreateResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_ORDER_CREATE)
                .addParam("itemId",requestBean.itemId)
                .addParam("tokenId",requestBean.tokenId)
                .addParam("currencyId",requestBean.currencyId)
                .addParam("side",requestBean.side)
                .addParam("price",requestBean.price)
                .addParam("quantity",requestBean.quantity)
                .addParam("amount",requestBean.amount)
                .addParam("curPrice",requestBean.curPrice)
                .addParam("tradePwd",MD5Utils.encode(requestBean.tradePwd))
                .addParam("flag",requestBean.flag)
                .build();
        HttpUtils.getInstance().request(params,OrderCreateResponse.class,listener);
    }

    /**
     * 撤单
     * @param orderId
     */
    public static void orderCancel(String orderId,SimpleResponseListener<ResultResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_ORDER_CANCEL)
                .addParam("orderId",orderId)
                .build();
        HttpUtils.getInstance().request(params,ResultResponse.class,listener);
    }


    /**
     * 获取订单详情
     * @param orderId
     * @param listener
     */
    public static void getOrderInfo(String orderId, SimpleResponseListener<OtcOrderInfoResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_ORDER_INFO)
                .addParam("orderId",orderId)
                .build();
        HttpUtils.getInstance().request(params,OtcOrderInfoResponse.class,listener);
    }


    /**
     * 确认放币，结束订单
     * @param orderId
     * @param tradePwd 交易密码 必填
     */
    public static void orderFinish(String orderId,String tradePwd,SimpleResponseListener<ResultResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_ORDER_FINISH)
                .addParam("orderId",orderId)
                .addParam("tradePwd",MD5Utils.encode(tradePwd))
                .build();
        HttpUtils.getInstance().request(params,ResultResponse.class,listener);
    }

    /**
     * 支付订单
     * @param orderId
     * @param paymentId 支付方式
     */
    public static void orderPay(String orderId,String paymentId,SimpleResponseListener<ResultResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_ORDER_PAY)
                .addParam("orderId",orderId)
                .addParam("id",paymentId)
                .build();
        HttpUtils.getInstance().request(params,ResultResponse.class,listener);
    }

    /**
     * 获取订单记录
     * @param listener
     */
    public static void getOrderList(int page,int pageSize,SimpleResponseListener<OrderHistoryResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_ORDER_LIST)
//                .addParam("status","40")
//                .addParam("tokenId","")
//                .addParam("side","")
                .addParam("page",page)
                .addParam("size",pageSize)
                .build();
        HttpUtils.getInstance().request(params,OrderHistoryResponse.class,listener);
    }

    /**
     * 获取待处理订单记录
     * @param listener
     */
    public static void getOrderPendingList(SimpleResponseListener<OrderPendingListResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_ORDER_PENDING_LIST)
                .build();
        HttpUtils.getInstance().request(params,OrderPendingListResponse.class,listener);
    }

    /**
     * 获取待处理订单数目
     * @param listener
     */
    public static void getOrderPendingCount(SimpleResponseListener<OrderPendingCountResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_ORDER_PENDING_LIST_COUNT)
                .build();
        HttpUtils.getInstance().request(params,OrderPendingCountResponse.class,listener);
    }

    /**
     * 订单申诉
     * @param orderId
     * @param appealType 0买方没有打款， 1卖方没有放币，2对方言语侮辱，3对方没有回复信息，4其他
     * @param appealContent 申诉内容
     */
    public static void orderAppeal(String orderId,int appealType,String appealContent,SimpleResponseListener<ResultResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_ORDER_APPEAL)
                .addParam("orderId",orderId)
                .addParam("appealType",appealType)
                .addParam("appealContent",appealContent)
                .build();
        HttpUtils.getInstance().request(params,ResultResponse.class,listener);
    }

}
